<template>
  <div>
    <el-tabs v-model="activeName" class="outer" @tab-click="handleClick">
      <el-tab-pane label="工单" name="first">
        <FormPanel ref="formPanel1" :list="formList1" :cols="3" :labelWidth="100" formType="show" :isSubmitBtn="false" />
      </el-tab-pane>
      <el-tab-pane label="备件销售单" name="second">
        <FormPanel ref="formPanel2" :list="formList2" :cols="3" formType="show" :isSubmitBtn="false" />
      </el-tab-pane>
    </el-tabs>
    <el-row style="margin-top:15px">
      <el-col :span="18">
        <el-tabs v-model="activeModel" class="outer" @tab-click="handleClick">
          <el-tab-pane label="维修项目" name="first">
            <FilterTable
              ref="table1"
              height="auto"
              :columns="columns1"
              selectionType="single"
              :datakey="''"
              :onColumnsChange="columns => (this.columns1 = columns)"
              :onRowSelectChange="arr => (this.onChangeColumn = arr)"
              :onSyncTableData="table1DataChange"
            ></FilterTable>
          </el-tab-pane>
          <el-tab-pane label="维修材料" name="second">
            <FilterTable
              ref="table2"
              height="auto"
              :columns="columns2"
              selectionType="single"
              :datakey="'rows'"
              :onColumnsChange="columns => (this.columns2 = columns)"
              :onRowSelectChange="arr => (this.onChangeColumn1 = arr)"
            ></FilterTable>
          </el-tab-pane>
          <el-tab-pane label="销售材料" name="three">
            <FilterTable
              ref="table3"
              height="auto"
              :columns="columns3"
              selectionType="single"
              :datakey="'rows'"
              :onColumnsChange="columns => (this.columns3 = columns)"
              :onRowSelectChange="arr => (this.onChangeColumn2 = arr)"
            ></FilterTable>
          </el-tab-pane>
          <el-tab-pane label="附加项目" name="four">
            <FilterTable
              ref="table4"
              height="auto"
              :columns="columns4"
              selectionType="single"
              :datakey="'rows'"
              :onColumnsChange="columns => (this.columns4 = columns)"
              :onRowSelectChange="arr => (this.onChangeColumn3 = arr)"
            ></FilterTable>
          </el-tab-pane>
        </el-tabs>
        <el-tabs v-model="activeBill" class="outer" style="margin-top: 15px" @tab-click="handleClick">
          <el-tab-pane label="应收" name="first">
            <FilterTable
              ref="table5"
              height="auto"
              :columns="columns5"
              selectionType="single"
              :datakey="'rows'"
              :onColumnsChange="columns => (this.columns5 = columns)"
              :onRowSelectChange="arr => (this.onChangeColumn4 = arr)"
            ></FilterTable>
          </el-tab-pane>
          <el-tab-pane label="实收" name="second">
            <FilterTable
              ref="table6"
              height="auto"
              :columns="columns6"
              selectionType="single"
              :datakey="'rows'"
              :onColumnsChange="columns => (this.columns6 = columns)"
              :onRowSelectChange="arr => (this.onChangeColumn5 = arr)"
            ></FilterTable>
          </el-tab-pane>
        </el-tabs>
      </el-col>
      <el-col :span="6">
        <FormPanel ref="formPanel3" :list="formList3" :cols="1" formType="show" :isSubmitBtn="false" />
      </el-col>
    </el-row>
    <!-- <BaseDialog :visible.sync="showChargeObject" title="收费对象拆分" width="800px" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <ChargeObject ref="chargeObject" @close="closeChargeObject" />
    </BaseDialog>-->
    <BaseDialog title="收费对象" :visible.sync="prePrintDialogShow" :width="'40%'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <PrePrint
        :printData="printData"
        @close="
          val => {
            this.prePrintDialogShow = val;
          }
        "
      />
    </BaseDialog>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <!-- <el-button type="primary" @click="prePrint">打 印</el-button> -->
      <el-button @click="closeDrawer">返 回</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import dictCode from '@/utils/dictCode';
import { sleep } from '@/utils';
import { searchRoleByCode, searchRoleByCodes } from '@/api/common/empSelect/index';
import {
  getRepairType,
  getPinpSelect,
  getChexSelect,
  getCheModelSelect,
  getDiscountMode,
  getInvoiceType,
  getWorkOrder,
  getSettlement,
  getRepairProject,
  getRepairMaterial,
  getSalesPo,
  getAddPo
} from '@/api/finance/repair/receivables';
import ChargeObject from '@/pages/finance/repairFinance/receivables/chargeObjectDialog';
import PrePrint from '@/pages/finance/repairFinance/receivables/prePrint.vue';
import { getAllUser } from '@/api/finance/advancesReceived/register';
import { queryPackUnit } from '@/api/part/common';
import { getSeriesList, getModelAllListOEM } from '@/api/common/cars/brandcarsModels'; // 车型车系
import { getBrand } from '@/api/part/common';

export default {
  name: 'Detail',
  components: {
    ChargeObject,
    PrePrint
  },
  mixins: [dictionary],
  props: {
    detailData: Object
  },
  data() {
    this.selectedRows = [];
    return {
      formList1: this.createFormList1(),
      formList2: this.createFormList2(),
      formList3: this.createFormList3(),
      columns1: this.createTableColumns1(),
      columns2: this.createTableColumns2(),
      columns3: this.createTableColumns3(),
      columns4: this.createTableColumns4(),
      columns5: this.createTableColumns5(),
      columns6: this.createTableColumns6(),
      onChangeColumn: [],
      onChangeColumn1: [],
      onChangeColumn2: [],
      onChangeColumn3: [],
      onChangeColumn4: [],
      onChangeColumn5: [],
      activeName: 'first',
      activeModel: 'first',
      activeBill: 'first',
      showChargeObject: false,
      prePrintDialogShow: false,
      brandCode: null,
      salerData: {}, // 人员数据(翻译用)
      printData: {} // 打印的数据
      // printTitle: '预打印'
    };
  },
  mounted() {
    this.getInvoiceType(); // 发票类型下拉
    this.serviceConsultant(); // 服务顾问下拉
    this.getRepairType(); // 维修类型下拉
    // this.getBrand() // 品牌下拉
    this.getDiscountMode(); // 优惠模式下拉
    this.searchRoleByCode(); // 技师
    this.queryAllUnitCode(); // 获取计量单位

    this.openModel(this.detailData);
  },
  methods: {
    createFormList1() {
      return [
        {
          type: 'INPUT',
          label: '工单号',
          fieldName: 'RO_NO'
        },
        {
          type: 'INPUT',
          label: '备件销售单号',
          fieldName: 'SALES_PART_NO'
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'LICENSE'
        },
        {
          type: 'INPUT',
          label: '结算单号',
          fieldName: 'BALANCE_NO'
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'VIN'
        },
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'OWNER_NAME'
        },
        {
          type: 'INPUT',
          label: '送修人',
          fieldName: 'DELIVERER'
        },
        {
          type: 'SELECT',
          itemList: [],
          label: '服务顾问',
          fieldName: 'SERVICE_ADVISOR'
        },
        {
          type: 'INPUT',
          label: '开单日期',
          fieldName: 'RO_CREATE_DATE',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'SELECT',
          itemList: [],
          label: '维修类型',
          fieldName: 'REPAIR_TYPE_CODE'
        },
        {
          type: 'SELECT',
          itemList: [],
          label: '品牌',
          fieldName: 'BRAND',
          change: val => {
            // this.changePinpSelect(val);
          }
        },
        {
          type: 'SELECT',
          itemList: [],
          label: '车系',
          fieldName: 'SERIES',
          change: val => {
            // this.changeChexSelect(val);
          }
        },
        {
          type: 'SELECT',
          itemList: [],
          label: '车型',
          fieldName: 'MODEL'
        },
        {
          type: 'INPUT',
          label: '行驶里程',
          fieldName: 'IN_MILEAGE'
        },
        {
          type: 'INPUT',
          label: '备注',
          fieldName: 'REMARK'
        },
        {
          type: 'INPUT',
          label: '检查结果',
          fieldName: 'RO_TROUBLE_DESC'
        }
      ];
    },
    createFormList2() {
      return [
        {
          type: 'INPUT',
          label: '客户代码',
          fieldName: 'CUSTOMER_CODE'
        },
        {
          type: 'INPUT',
          label: '客户名称',
          fieldName: 'CUSTOMER_NAME'
        }
      ];
    },
    createFormList3() {
      return [
        {
          // type: 'SELECT',
          // itemList: [],
          // label: '优惠模式',
          // fieldName: 'DISCOUNT_MODE_CODE',
          type: 'SELECT',
          label: '优惠模式',
          fieldName: 'DISCOUNT_MODE_CODE',
          placeholder: '请选择',
          itemList: []
        },
        // {
        //   type: 'INPUT',
        //   label: '发票编号',
        //   fieldName: 'INVOICE_NO'
        // },
        // {
        //   type: 'SELECT',
        //   itemList: [],
        //   label: '发票类型',
        //   fieldName: 'INVOICE_TYPE_CODE'
        // },
        // {
        //   type: 'SELECT',
        //   itemList: this.createDictList('8044'),
        //   label: '付款方式',
        //   fieldName: 'PAY_TYPE_CODE'
        // },
        // {
        //   type: 'SELECT',
        //   itemList: this.createDictList('1207'),
        //   label: '保险公司',
        //   fieldName: 'INSURATION_CODE'
        // },
        // {
        //   type: 'INPUT',
        //   label: '理赔单号',
        //   fieldName: 'INSURATION_NO'
        // },
        // {
        //   type: 'SELECT',
        //   itemList: this.createDictList('1278'),
        //   label: '是否欠款选中',
        //   fieldName: 'ARR_BALANCE'
        // },
        {
          type: 'INPUT_NUMBER',
          label: '总金额',
          precision: 2,
          fieldName: 'TOTAL_AMOUNT'
        },
        {
          type: 'INPUT_NUMBER',
          label: '税率',
          precision: 2,
          fieldName: 'TAX'
        },
        {
          type: 'INPUT_NUMBER',
          label: '税额',
          precision: 2,
          fieldName: 'TAX_AMOUNT'
        },
        {
          type: 'INPUT_NUMBER',
          label: '不含税金额',
          precision: 2,
          fieldName: 'NET_AMOUNT'
        },
        {
          type: 'INPUT_NUMBER',
          label: '去零金额',
          precision: 2,
          fieldName: 'SUB_OBB_AMOUNT'
        },
        // {
        //   type: 'INPUT',
        //   label: '抵扣金额',
        //   precision: 2,
        //   fieldName: 'GIFT_AMOUNT'
        // },
        {
          type: 'INPUT_NUMBER',
          label: '收款金额',
          precision: 2,
          fieldName: 'RECEIVE_AMOUNT'
        }
      ];
    },
    createTableColumns1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   width: 50,
        //   fixed: 'left',
        //   render: props => {
        //     return (
        //       <div>
        //         <el-button size="mini" type="text" onClick={() => this.openChargeObject(props.row)}>
        //           明细
        //         </el-button>
        //       </div>
        //     );
        //   }
        // },
        // {
        //   title: '收费类别',
        //   dataIndex: 'MANAGE_SORT_NAME',
        //   sorter: true
        // },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_NAME',
          sorter: true
        },
        {
          title: '项目维修类型',
          dataIndex: 'REPAIR_TYPE_NAME',
          sorter: true
        },
        {
          title: '故障原因',
          dataIndex: 'TROUBLE_DESC',
          sorter: true
        },
        {
          title: '项目代码',
          dataIndex: 'LABOUR_CODE',
          sorter: true
        },
        {
          title: '项目名称',
          dataIndex: 'LABOUR_NAME',
          width: 150,
          sorter: true,
          showOverflowTooltip: true
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '责任技师',
          dataIndex: 'TECHNICIAN_NAMES_TRANSED',
          sorter: true
          // editable: false,
          // editType: 'select',
          // editItems: []
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '折扣金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '实收金额',
          dataIndex: 'REAL_RECEIVE_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '标准工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          precision: 2,
          sorter: true
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true
        },
        {
          title: '检查结果',
          dataIndex: 'RO_TROUBLE_DESC',
          sorter: true
        },
        {
          title: '组合代码',
          dataIndex: 'PACKAGE_CODE',
          sorter: true
        },
        {
          title: '车系',
          dataIndex: 'MODEL_LABOUR_NAME',
          sorter: true
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true
        }
      ];
    },
    createTableColumns2() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   width: 50,
        //   fixed: 'left',
        //   render: props => {
        //     return (
        //       <div>
        //         <el-button size="mini" type="text" onClick={() => this.openChargeObject(props.row)}>
        //           明细
        //         </el-button>
        //       </div>
        //     );
        //   }
        // },
        // {
        //   title: '收费类别',
        //   dataIndex: 'MANAGE_SORT_NAME',
        //   sorter: true
        // },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_NAME',
          sorter: true
        },
        {
          title: '备件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          showOverflowTooltip: true
        },
        {
          title: '备件销售单价',
          dataIndex: 'PART_SALES_PRICE',
          precision: 2,
          sorter: true
        },
        {
          title: '备件数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true
        },
        {
          title: '备件销售金额',
          dataIndex: 'PART_SALES_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '实收金额',
          dataIndex: 'REAL_RECEIVE_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          sorter: true
        },
        {
          title: '计量单位',
          dataIndex: 'UNIT_CODE',
          sorter: true,
          dictItems: []
        },
        {
          title: '备件代码',
          dataIndex: 'PART_NO',
          sorter: true
        },
        {
          title: '是否委外',
          dataIndex: 'CONSIGN_EXTERIOR',
          sorter: true,
          editType: 'select',
          editItems: this.createDictList('1004')
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true
        },
        {
          title: '维修项目代码',
          dataIndex: 'LABOUR_CODE',
          sorter: true
        },
        {
          title: '车系',
          dataIndex: 'MODEL_LABOUR_NAME',
          sorter: true
        },
        {
          title: '组合代码',
          dataIndex: 'PACKAGE_CODE',
          sorter: true
        },
        {
          title: '不可打折',
          dataIndex: 'IS_DISCOUNT',
          sorter: true
        },
        {
          title: '备件类别',
          dataIndex: 'PART_CATEGORY',
          sorter: true
        }
      ];
    },
    createTableColumns3() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          sorter: true
        },
        {
          title: '仓库名称',
          dataIndex: 'STORAGE_NAME',
          sorter: true
        },
        {
          title: '备件代码',
          dataIndex: 'PART_NO',
          sorter: true
        },
        {
          title: '备件名称',
          dataIndex: 'PART_NAME',
          sorter: true,
          showOverflowTooltip: true
        },
        {
          title: '备件销售数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true
        },
        {
          title: '计量单位',
          dataIndex: 'UNIT_CODE',
          sorter: true
        },
        {
          title: '备件销售单价',
          dataIndex: 'PART_SALES_PRICE',
          sorter: true
        },
        {
          title: '备件销售金额',
          dataIndex: 'PART_SALES_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '实收金额',
          dataIndex: 'REAL_RECEIVE_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '不可打折',
          dataIndex: 'IS_DISCOUNT',
          sorter: true
        }
      ];
    },
    createTableColumns4() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // {
        //   title: '操作',
        //   dataIndex: 'column-action',
        //   width: 50,
        //   fixed: 'left',
        //   render: props => {
        //     return (
        //       <div>
        //         <el-button size="mini" type="text" onClick={() => this.openChargeObject(props.row)}>
        //           明细
        //         </el-button>
        //       </div>
        //     );
        //   }
        // },
        // {
        //   title: '收费类别',
        //   dataIndex: 'MANAGE_SORT_NAME',
        //   sorter: true
        // },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_NAME',
          sorter: true
        },
        {
          title: '附加项目代码',
          dataIndex: 'ADD_ITEM_CODE',
          sorter: true
        },
        {
          title: '附加项目名称',
          dataIndex: 'ADD_ITEM_AMOUNT',
          sorter: true,
          showOverflowTooltip: true
        },
        {
          title: '折让金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '实收金额',
          dataIndex: 'REAL_RECEIVE_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          sorter: true
        },
        {
          title: '活动编码',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true
        }
      ];
    },
    createTableColumns5() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费对象代码',
          dataIndex: 'PAYMENT_OBJECT_CODE',
          sorter: true
        },
        {
          title: '收费对象名称',
          dataIndex: 'PAYMENT_OBJECT_NAME',
          sorter: true
        },
        {
          title: '应收工时费',
          dataIndex: 'RECEIVEABLE_LABOUR_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '应收维修材料费',
          dataIndex: 'RECEIVEABLE_REPAIR_PART_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '应收销售材料费',
          dataIndex: 'RECEIVEABLE_SALES_PART_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '应收附加项目费',
          dataIndex: 'RECEIVEABLE_ADD_ITEM_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '应收辅料管理费',
          dataIndex: 'RECEIVEABLE_OVER_ITEM_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '应收装饰项目费',
          dataIndex: 'RECEIVEABLE_BOUTIQUE_ITEM_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '应收装饰材料费',
          dataIndex: 'RECEIVEABLE_BOUTIQUE_PART_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '应收总金额',
          dataIndex: 'RECEIVEABLE_TOTAL_AMOUNT',
          precision: 2,
          sorter: true
        }
      ];
    },
    createTableColumns6() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '收费对象代码',
          dataIndex: 'PAYMENT_OBJECT_CODE',
          sorter: true
        },
        {
          title: '收费对象名称',
          dataIndex: 'PAYMENT_OBJECT_NAME',
          sorter: true
        },
        {
          title: '实收工时费',
          dataIndex: 'REAL_LABOUR_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '实收维修材料费',
          dataIndex: 'REAL_REPAIR_PART_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '实收销售材料费',
          dataIndex: 'REAL_SALES_PART_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '实收附加项目费',
          dataIndex: 'REAL_ADD_ITEM_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '实收辅料管理费',
          dataIndex: 'REAL_OVER_ITEM_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '实收装饰项目费',
          dataIndex: 'REAL_BOUTIQUE_ITEM_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '实收装饰材料费',
          dataIndex: 'REAL_BOUTIQUE_PART_FEE',
          precision: 2,
          sorter: true
        },
        {
          title: '汇总金额',
          dataIndex: 'SUM_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '实收总金额',
          dataIndex: 'REAL_TOTAL_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '税额',
          dataIndex: 'TAX_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '不含税金额',
          dataIndex: 'NET_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '去零金额',
          dataIndex: 'SUB_OBB_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '应收账款',
          dataIndex: 'RECEIVABLE_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '已收账款',
          dataIndex: 'RECEIVED_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '未收账款',
          dataIndex: 'NOT_RECEIVED_AMOUNT',
          precision: 2,
          sorter: true
        },
        {
          title: '是否结清',
          dataIndex: 'PAY_OFF',
          sorter: true,
          editType: 'select',
          editItems: this.createDictList('1004')
        },
        {
          title: '已开票',
          dataIndex: 'INVOICE_TAG',
          sorter: true,
          editType: 'select',
          editItems: this.createDictList('1004')
          // render: props => {
          //   return <span>{this.createDictList(Number(props.row.INVOICE_TAG),'1004')}</span>;
          // }
        }
      ];
    },
    openModel(data) {
      console.log(data, 'data');
      this.getWorkOrder(data.BALANCE_NO, data.OWNER_CODE); // 获取销账信息
      this.getSettlement(data.OWNER_CODE, data.BALANCE_NO); // 结算表单
      this.getRepairProject(data.OWNER_CODE, data.BALANCE_NO); // 维修项目表格
      this.getRepairMaterial(data.OWNER_CODE, data.BALANCE_NO); // 维修材料表格
      this.getSalesPo(data.OWNER_CODE, data.BALANCE_NO); // 销售材料表格
      this.getAddPo(data.OWNER_CODE, data.BALANCE_NO); // 附加项目表格
      // this.formList1[3].initialValue = data.BALANCE_NO
      this.printData = data;
      this.formList1.find(item => item.fieldName === 'BALANCE_NO').initialValue = data.BALANCE_NO;
      this.formList1.map(item => {
        if (data[item.fieldName]) {
          item.initialValue = data[item.fieldName];
        }
      });

      // for (let [key, value] of Object.entries(data)) {
      //   this.formList1.some(item => {
      //     if (item.fieldName === key) {
      //       item.initialValue = value;
      //       return true;
      //     }
      //   });
      // }
      let { BRAND, SERIES, MODEL } = data;
      this.getbrandsdictListFun();
      if (BRAND) {
        this.selectSeriesFun({ brandsid: BRAND });
      }
      if (SERIES && BRAND) {
        this.selectModelFun({ brandsid: BRAND, seriessid: SERIES });
      }
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    async serviceConsultant() {
      let testDrive = { role: dictCode.SERVICE_CONSULTANT };
      const res = await searchRoleByCode(testDrive);
      // console.log(res, '服务顾问');
      this.formList1.find(item => item.fieldName === 'SERVICE_ADVISOR').itemList = res.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
    },
    async getRepairType() {
      const res = await getRepairType();
      console.log(res, 'res----');
      this.formList1.find(item => item.fieldName === 'REPAIR_TYPE_CODE').itemList = res.data.map(x => ({ value: x.REPAIR_TYPE_CODE + '', text: x.REPAIR_TYPE_NAME }));
    },
    // 获取品牌 ——下拉框
    async getBrand() {
      this.formList1.find(item => item.fieldName === 'BRAND').itemList = (await getPinpSelect()).data.map(x => ({ text: x.brandName, value: x.brandId }));
    },

    // 品牌下拉框改变时
    changePinpSelect(id) {
      this.brandCode = id;
      if (!id) return;
      this.getSeries(id);
    },

    // 车系下拉框改变时
    changeChexSelect(id) {
      if (!id) return;
      this.getCheModelSelect(this.brandCode, id);
    },

    // 获取品牌信息
    async getbrandsdictListFun() {
      // const res = await getbrandsdictList(this.dmsFunc);
      const res = await getBrand();
      this.formList1.find(item => item.fieldName === 'BRAND').itemList = res.data.map(x => ({ value: x.BRAND_ID + '', text: x.BRAND_NAME }));
    },
    // 获取车系信息
    async selectSeriesFun(param) {
      console.log(param, '获取车系信息参数');
      // const res = await selectSeries(param);
      const res = await getSeriesList(param.brandsid);
      this.formList1.find(item => item.fieldName === 'SERIES').itemList = res.data.map(x => ({ value: x.seriesId + '', text: x.seriesName }));
    },
    // 获取车型信息
    async selectModelFun(param) {
      console.log(param, '获取车型信息参数');
      // const res = await selectModel(param);
      const res = await getModelAllListOEM(param.brandsid, param.seriessid);
      this.formList1.find(item => item.fieldName === 'MODEL').itemList = res.data.map(x => ({ value: x.modelId + '', text: x.modelName }));
    },

    async getSeries(id) {
      this.formList1.find(item => item.fieldName === 'SERIES').itemList = (await getChexSelect(id)).data.map(x => ({ text: x.seriesName, value: x.seriesId }));
    },

    async getCheModelSelect(brandCode, id) {
      this.formList1.find(item => item.fieldName === 'MODEL').itemList = (await getCheModelSelect(brandCode, id)).data.map(x => ({ text: x.modelName, value: x.modelId }));
    },

    async getDiscountMode() {
      const res = await getDiscountMode();
      this.formList3.find(item => item.fieldName === 'DISCOUNT_MODE_CODE').itemList = res.data.map(x => ({ value: x.DISCOUNT_MODE_CODE, text: x.DISCOUNT_MODE_NAME }));
    },
    async getInvoiceType() {
      const res = await getInvoiceType();
      // console.log(res)
      // this.formList3.find(item => item.fieldName === 'INVOICE_TYPE_CODE').itemList = res.data.map(x => ({ value: x.INVOICE_TYPE_CODE, text: x.INVOICE_TYPE_NAME }));
    },
    async getWorkOrder(id, code) {
      const res = await getWorkOrder(id, code);
      // console.log('getWorkOrder',res)
      console.log('****res', res);
      for (let [key, value] of Object.entries(res.data)) {
        this.formList1.some(item => {
          if (item.fieldName === key) {
            value && (item.initialValue = value);
            return true;
          }
        });
      }
      for (let [key, value] of Object.entries(res.data)) {
        this.formList2.some(item => {
          if (item.fieldName === key) {
            item.initialValue = value;
            return true;
          }
        });
      }
      for (let [key, value] of Object.entries(res.data)) {
        this.formList3.some(item => {
          if (item.fieldName === key) {
            item.initialValue = value;
            return true;
          }
        });
      }
    },
    async getSettlement(id, code) {
      const res = await getSettlement(id, code);
      // for (let [key, value] of Object.entries(res.data[0])) {
      //   this.formList3.some(item => {
      //     if (item.fieldName === key) {
      //       item.initialValue = value;
      //       return true;
      //     }
      //   });
      // }
      this.$refs.table5.$refs.pageTable.EXECUTE_INSERT(res.data);
      this.$refs.table6.$refs.pageTable.EXECUTE_INSERT(res.data);
    },
    async getRepairProject(id, code) {
      const res = await getRepairProject(id, code);
      console.log('维修项目', res);
      // console.log('res',res)
      this.$refs.table1.$refs.pageTable.EXECUTE_INSERT(res.data);
    },
    async getRepairMaterial(id, code) {
      const res = await getRepairMaterial(id, code);
      // console.log('res',res)
      this.$refs.table2.$refs.pageTable.EXECUTE_INSERT(res.data);
    },
    async getSalesPo(id, code) {
      const res = await getSalesPo(id, code);
      console.log('res', res);
      this.$refs.table3.$refs.pageTable.EXECUTE_INSERT(res.data);
    },
    async getAddPo(id, code) {
      const res = await getAddPo(id, code);
      console.log('res', res);
      this.$refs.table4.$refs.pageTable.EXECUTE_INSERT(res.data);
    },
    async searchRoleByCode() {
      let technician = { role: dictCode.TECHNICIAN };
      const technicianRes = await searchRoleByCodes(technician);
      console.log('技师信息', technicianRes);
      // this.columns1.find(x => x.dataIndex === 'TECHNICIAN').editItems = technicianRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      let obj = {};
      technicianRes.data.map(item => {
        obj[item.userId] = item.employeeName;
      });
      this.salerData = obj;
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    closeDrawer(list) {
      this.$emit('close', false, list);
    },
    // openChargeObject(data) {
    //   this.showChargeObject = true;
    //   this.$nextTick(() => {
    //     this.$refs.chargeObject.openModel(data);
    //   });
    // },
    closeChargeObject() {
      this.showChargeObject = false;
    },
    prePrint() {
      // this.$set(this.printData, 'BALANCE_REMARK', this.feesSettlementList.find(item=>item.fieldName==='BALANCE_REMARK').initialValue);
      this.prePrintDialogShow = true;
      // this.printTitle = '预打印';
    },
    // 维修项目table数据改变（翻译多人技师）
    async table1DataChange(e) {
      console.log(e, 'table1数据变化');
      if (!Object.keys(this.salerData).length) {
        let technician = { role: dictCode.TECHNICIAN };
        const technicianRes = await searchRoleByCodes(technician);
        let obj = {};
        technicianRes.data.map(item => {
          obj[item.userId] = item.employeeName;
        });
        this.salerData = obj;
      }
      await sleep(600);
      this.$nextTick(() => {
        e.map(item => {
          console.log(item.TECHNICIAN_NAMES, 11111111111);
          let arr = item.TECHNICIAN_NAMES.split(',');
          let nameArr = [];
          arr.map(item2 => {
            nameArr.push(this.salerData[item2]);
          });
          item.TECHNICIAN_NAMES_TRANSED = nameArr.join(',');
        });
      });
    },
    // 获取计量单位
    async queryAllUnitCode() {
      let res = await queryPackUnit();
      this.columns2.find(item => item.dataIndex == 'UNIT_CODE').dictItems = res.data.map(item => ({
        text: item.UNIT_NAME,
        value: item.UNIT_CODE
      }));
    }
  }
};
</script>

<style lang="less" scoped>
.wrapper {
  height: calc(100vh - 238px);
}
.box {
  border: 1px solid #ccc;
  padding-top: 15px;
  padding-right: 15px;
  border-radius: @borderRadius;
  margin-bottom: 20px;
  box-shadow: @boxShadow;
}
.outer {
  border: 1px solid @borderColor;
  border-radius: @borderRadius;
  box-shadow: @boxShadow;
  padding: @modulePadding;
}
</style>
